package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.AdminDto;
import com.qs.pojo.dto.UserDto;
import com.qs.pojo.entity.Admin;
import com.qs.pojo.entity.User;
import com.qs.pojo.vo.PasswordVo;
import com.qs.pojo.vo.PersonalVo;
import com.qs.pojo.vo.UserVo;
import com.qs.response.Response;
import com.qs.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 普通用户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-12
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;

    /**
     * 获取普通用户分页数据
     * @param pageNo
     * @param pageSize
     * @param userVo
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable Integer pageNo,
                         @PathVariable Integer pageSize,
                         UserVo userVo) {
        log.info("获取普通用户分页数据请求进来--------------------");
        Map<String,Object> userMap = userService.getList(pageNo,pageSize,userVo);
        return Response.success(userMap);
    }

    /**
     * 新增普通用户
     * @param user
     * @return
     */
    @PostMapping("/save")
    @OperationLog(operModul = "用户管理-新增用户",operDesc = "新增普通用户")
    public Response saveAdmin(@RequestBody User user) {
        log.info("新增普通用户请求进来--------------------");
        userService.saveUser(user);
        return Response.success();
    }

    /**
     * 用户实名认证接口
     * @param user
     * @return
     */
    @PostMapping("/certification")
    public Response certification(@RequestBody User user) {
        log.info("用户实名认证接口请求进来--------------------");
        UserDto userDto = userService.certification(user);
        return Response.success(userDto);
    }

    /**
     * 用户修改密码接口
     * @param passwordVo
     * @return
     */
    @PostMapping("/update/password")
    public Response updatePassword(@RequestBody PasswordVo passwordVo) {
        log.info("用户修改密码接口请求进来--------------------");
        userService.updatePassword(passwordVo);
        return Response.success();
    }

    /**
     * 用户信息修改接口
     * @param personalVo
     * @return
     */
    @PostMapping("/update/personal")
    public Response updatePersonal(@RequestBody PersonalVo personalVo) {
        log.info("用户信息修改接口请求进来--------------------");
        userService.updatePersonal(personalVo);
        return Response.success();
    }

    /**
     * 用户信息修改数据回显接口
     * @param id
     * @return
     */
    @GetMapping("/echo/personal/{id}")
    public Response echoPersonal(@PathVariable("id") Integer id) {
        log.info("用户信息修改数据回显接口请求进来--------------------");
        PersonalVo personalVo = userService.echoPersonal(id);
        return Response.success(personalVo);
    }

    /**
     * 修改普通用户
     * @param
     * @param
     * @param
     * @return
     */
    @PutMapping("/update")
    public Response update(@RequestBody UserDto userDto) {
        log.info("修改普通用户请求进来--------------------");
        userService.updateByKey(userDto);
        return Response.success();
    }

    /**
     * 普通用户数据回显
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/getById/{id}")
    public Response echo(@PathVariable Integer id) {
        log.info("普通用户数据回显请求进来--------------------");
        UserDto userDto = userService.echo(id);
        return Response.success(userDto);
    }

    /**
     * 删除普通用户
     * @param
     * @param
     * @param
     * @return
     */
    @DeleteMapping("/remove/{ids}")
    @OperationLog(operModul = "用户管理-删除用户",operDesc = "删除普通用户")
    public Response delete(@PathVariable List<Integer> ids) {
        log.info("删除普通用户请求进来--------------------");
        userService.deleteBatchByIds(ids);
        return Response.success();
    }
}
